﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.LogicalGroups.CApGroupTypeValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.LogicalGroups;

internal class CApGroupTypeValidator : ITxValidator
{
  private ITxTypeFilter m_filter;
  private string m_invalidObjMessage;
  private string m_missingObjMessage;
  private ValidateGroupObject m_validatePickedObject;

  internal CApGroupTypeValidator(ITxTypeFilter filter, ValidateGroupObject validatePickedObject)
  {
    this.m_filter = filter;
    this.m_invalidObjMessage = LGRLogicalGroupResource.GROUP_TYPE_INVALID_OBJECT;
    this.m_missingObjMessage = LGRLogicalGroupResource.GROUP_TYPE_MISSING_OBJECT;
    this.m_validatePickedObject = validatePickedObject;
  }

  public ITxObject GetObject(string text)
  {
    ITxObject itxObject = (ITxObject) null;
    TxObjectList objectsByName = TxApplication.ActiveDocument.GetObjectsByName(text);
    for (int index = 0; index < ((Collection<ITxObject>) objectsByName).Count && itxObject == null; ++index)
    {
      if (this.DoesPassFilter(((Collection<ITxObject>) objectsByName)[index]))
        itxObject = ((Collection<ITxObject>) objectsByName)[index];
    }
    return itxObject;
  }

  public string GetText(ITxObject obj)
  {
    string text = (string) null;
    try
    {
      text = obj.Name;
    }
    catch (TxException ex)
    {
    }
    return text;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    errorMessage = (string) null;
    bool flag = this.DoesPassFilter(obj);
    if (!flag)
      errorMessage = this.m_invalidObjMessage;
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    errorMessage = (string) null;
    bool flag = false;
    if (text == string.Empty)
      errorMessage = this.m_missingObjMessage;
    else if (this.GetObject(text) != null)
      flag = true;
    else
      errorMessage = this.m_invalidObjMessage;
    return flag;
  }

  private bool DoesPassFilter(ITxObject obj)
  {
    bool flag = this.m_filter.DoesPassFilter(obj);
    if (flag && this.m_validatePickedObject != null)
      flag = this.m_validatePickedObject(obj);
    return flag;
  }
}
